package oceanlife;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


public class OLSet{
	public static int border = 10000;
	private static int config_id = 1;
	private static Map<String,String> buffer = new HashMap<String,String>();
	private static boolean configRead = readConfig();
	private static double cps;
	private static int agents;
	private static double x_size;
	private static double y_size;
	//private static ArrayList<Integer> obstacleSets;
	
	/*public static Integer[] getObstacleSets() {
		int[] obsSet = new int[obstacleSets.size()];
		
		return obstacleSets.toArray(new Integer[0]);
	}*/

	private static boolean readConfig(){
		cps = 100;
		agents = 0;
		x_size = 0;
		y_size = 0;
		buffer.put("scale", "1");
		/*db.init();
	    ResultSet configResult = db.exec("select * from ocean_life.configuration where idconfiguration = "+config_id+";");
	    try {
			if(configResult.next()){
				cps = Float.parseFloat(configResult.getString(2));
				agents = Integer.parseInt(configResult.getString(3));
				x_size = Float.parseFloat(configResult.getString(4));
				y_size = Float.parseFloat(configResult.getString(5));
			} else {
				System.out.println("no config found");
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	    ResultSet obstacleResult = db.exec("SELECT DISTINCT obstacle_set_id FROM `ocean_life`.`obstacle_set`;");
	    try {
			obstacleSets = new ArrayList<Integer>();
			while(obstacleResult.next()){
				obstacleSets.add(obstacleResult.getInt(1));
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}*/
		return true;
	}
	
	public static int getConfig_id() {
		return config_id;
	}

	public static double getCps() {
		return cps;
	}

	public static int getAgents() {
		return agents;
	}

	public static double getX_size() {
		return x_size;
	}

	public static double getY_size() {
		return y_size;
	}

	public static String get(String key){
		String result = buffer.get(key);
		return result;
		/*if (result != null){
			return result;
		} else {		
			try {
				ResultSet resultSet = db.exec("select * from ocean_life.misc_hash where `key` = '"+key+"';");
				if (resultSet == null){
					return "";
				} else {
					resultSet.next();
					buffer.put(key, resultSet.getString(2));
					return resultSet.getString(2);
				}
			} catch (SQLException e) {
				return null;
				//e.printStackTrace();
			}
		}*/
	}
	
	public static int getInt(String key){
		return Integer.parseInt(get(key));
	}
	
	public static float getFloat(String key){
		return Float.parseFloat(get(key));
	}
	
	public static double getDouble(String key) {
		return Double.parseDouble(get(key));
	}

	public static void set(String key, String value){
		buffer.put(key, value);
		/*if (db.exec("INSERT INTO `ocean_life`.`misc_hash` (`key`, `value`) VALUES ('"+key+"', '"+value+"');") == null){
			ResultSet temp = db.exec("UPDATE `ocean_life`.`misc_hash` SET `value`='"+value+"' WHERE `key`='"+key+"';");
		}*/
	}

	public static void setInt(String key, int value){
		set(key,Integer.toString(value));
	}
	
	public static void setFloat(String key, float value){
		set(key,Float.toString(value));
	}

	public static void setDouble(String key, double value){
		set(key,Double.toString(value));
	}
	

}
